
#ifndef  ILOG_H
#define  ILOG_H

#include "recovery/Status.h"

class Topic;

class ILogSize {
public:	
    ILogSize(size_t size) : _size(size) {}
    virtual ~ILogSize() {}

    virtual size_t value() const { return _size; }
    virtual void value(size_t size) { _size = size; }

	virtual ILogSize & reset(){
		return this->overwrite(0);
	}
    virtual ILogSize & advance(size_t delta) {
        return this->overwrite( value() + delta);
    }
    virtual ILogSize & overwrite(size_t fileSize) = 0;

    virtual recovery::Status sync() = 0;
private:
    size_t _size;
};

class IMeta {
public:
	static IMeta * create(Topic & topic);

	virtual ~IMeta(){}

	virtual ILogSize & logSize() const = 0;

    virtual size_t size() const = 0;

	virtual recovery::Status load() = 0; // synced(true) after load 
	virtual recovery::Status sync() = 0;
	virtual recovery::Status reset() = 0;

	bool isSync() const { return _synced; }
    void synced(bool synced){ _synced = synced; }
	
    virtual recovery::Status open() = 0;
    virtual recovery::Status close()  = 0;
	virtual bool isOpen() = 0;

private:
    bool _synced = false;
};

class ILog {
public:
	static ILog * create(Topic & topic);

    virtual ~ILog(){};

	virtual recovery::Status open() = 0;
	virtual recovery::Status close() = 0;

	virtual recovery::Status append(const std::string & data, size_t & appendedBytes) = 0;
    virtual recovery::Status sync() = 0;
    virtual recovery::Status truncate(size_t size) = 0;

    virtual recovery::Status size(size_t & sz) const = 0;

    virtual IMeta & meta() = 0;

};

#endif   /* ILOG_H */
